package com.fa4j.system.login.controller;

import com.fa4j.system.login.LoginSessionClient;
import com.fa4j.system.login.convert.LoginConverter;
import com.fa4j.system.login.dto.LoginSessionDTO;
import com.fa4j.system.login.service.LoginSessionService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Hidden
@Tag(name = "登录")
@Slf4j
@RestController
@RequestMapping("system/login")
@RequiredArgsConstructor
public class LoginSessionApiController implements LoginSessionClient {

    private final LoginSessionService loginSessionService;

    private final LoginConverter loginConverter;

    @Override
    public LoginSessionDTO getSession(String token) {
        return loginSessionService.get(token)
                .map(loginConverter::toSessionDTO)
                .orElse(null);
    }
}
